<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Message extends Start_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->_model('model_message','message');
 	}
	
	
	public function index()
	{
		$this->_FeedBack(); 
	}
	public function glist(){
		
		$per_page = 10;
		
	 	$page = $this->uri->segment(3);
	 	
	     if(empty($page)){
	        $start = 0;
	     }else{
	        $start = ($page-1)*$per_page;
	     }
		
	     
		//取得信息列表
		$data['message'] = $this->message->find_all('','*','id desc',$start, $per_page);
		
		//分页
		$config['base_url'] = site_url('message/listall/');
		$config['total_rows'] = $this->message->find_count();
		$config['per_page'] = $per_page;
		$config['uri_segment'] = 3;
		//分页数据显示的标签
		$config['full_tag_open'] = '<div>';
		$config['full_tag_close'] = '</div>';
		//当前页的其实标签 ?: 加粗一下
		$config['cur_tag_open'] = '<b>';
		$config['cur_tag_close'] = '</b>';
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$config['use_page_numbers'] = TRUE;
		//当前页先后个显示的个数
		$config['num_links'] = 9;
		
		$this->load->library('pagination'); //载入分页类
		$this->pagination->initialize($config); 
		$page = $this->pagination->create_links();
		
		$data['page'] =  $page;
		
		$this->data['message'] = $data['message'];
		$this->data['page'] = $data['page'];
		$this->data['pagename'] = '留言列表';
		
		$this->_template('message',$this->data);
		
	}
	public function _FeedBack(){
		 

		$post = $this->input->post(NULL, TRUE);

		if(isset($post['btnSubmit'])){
			 $post['addtime'] = time();
 			 $this->message->insert($post);
			 $this->_message('添加留言成功！我们会尽快给您回复。'.'<p><a href="javascript:history.back(-1);">返回上一页</a></p>',200,'成功提示' );
		}
		
		$this->data['pagename'] = '我要留言';
		$this->_template('message',$this->data);
		
		
	}
}
